using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class Hud : MonoBehaviour
{
    public GameManager gameManager;
    public Texture2D reticule;
    public Vector2 healthBarSize = new Vector2(256, 32);
    public Texture2D progressBarEmpty;
    public Texture2D progressBarFull;

    public PlayerCamera playerCamera;
    public VehicleController playerVehicle;
    public WeaponsController playerWeapons;
    public HealthController playerHealth;

    public Chat chat;

    public void DrawGUI()
    {
        //draw the reticule
        GUI.DrawTexture(new Rect(Screen.width / 2 - (reticule.width * 0.5f), Screen.height / 2 - (reticule.height * 0.5f), reticule.width, reticule.height), reticule);

        //draw target health
        if (playerCamera.isTargetEnemy)
        {
            GUILayout.BeginArea(new Rect(Screen.width / 2 + (reticule.width * 0.5f) + 10f, Screen.height / 2 - 25, 50, 50));
            GUILayout.Label(playerCamera.targetName);
            GUILayout.Label(playerCamera.targetHealth + "%");
            GUILayout.EndArea();
        }

        //display chat
        //chat.SetWindowChat(5, Screen.height - 100, 195, 90);
        //chat.DrawChat();

        //Display the equiped weapons
        GUILayout.BeginArea(new Rect(Screen.width * 0.80f, Screen.height - 50, Screen.width * 0.20f, 50));
        GUILayout.Label(playerWeapons.primaryWeapon.weaponName + " | " + playerWeapons.secondaryWeapon.weaponName);
        GUILayout.Label("Durability : " + playerHealth.health + "/" + playerHealth.maxHealth);
        GUILayout.EndArea();

        //// draw the background:
        //GUI.BeginGroup(new Rect(0, 80, healthBarSize.x, healthBarSize.y));
        //GUI.DrawTexture(new Rect(0, 0, healthBarSize.x, healthBarSize.y), progressBarEmpty);
        //// draw the filled-in part:
        //GUI.BeginGroup(new Rect(0, 0, healthBarSize.x * playerHealth.health / playerHealth.maxHealth, healthBarSize.y));
        //GUI.DrawTexture(new Rect(0, 0, healthBarSize.x, healthBarSize.y), progressBarFull);
        //GUI.EndGroup();
        //GUI.EndGroup();

        //speed km/h
        //int speed = (int)(playerVehicle.rigidbody.velocity.magnitude * 3.6f);
        //GUI.Box(new Rect(10, Screen.height - 60, 80, 20), speed.ToString() + " km/h");

        //Display scores
        GUI.Box(new Rect(Screen.width - 150, 10, 145, 200), "Scores");
        GUILayout.BeginArea(new Rect(Screen.width - 150, 10, 145, 200));
        GUILayout.Space(20);
        GUILayout.Label("Kills to win : " + gameManager.maxKills);
        foreach (KeyValuePair<string, PlayerScore> score in gameManager.scores.scoresData)
        {
            GUILayout.Label(score.Key + ": " + score.Value.nbKill + " | " + score.Value.nbDead);
        }
        GUILayout.EndArea();
    }
}
